<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:UsageStats">


    <Style TargetType="{x:Type local:BarChart}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:BarChart}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="PART_Title" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" Padding="10" Text="{TemplateBinding Title}"/>
                            <TextBlock x:Name="PART_HorizontalAxisTitle" Grid.Row="2" HorizontalAlignment="Center" Padding="2" Text="{TemplateBinding HorizontalAxisTitle}"/>
                            <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
                                <ItemsControl x:Name="PART_Items" ItemsSource="{TemplateBinding ItemsSource}" Padding="4 0 4 4" HorizontalAlignment="Center">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel VerticalAlignment="Bottom" Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel VerticalAlignment="Bottom">
                                                <TextBlock HorizontalAlignment="Center" Text="{Binding Value}" FontSize="10"/>
                                                <Rectangle Width="30" Height="{Binding Value}" Margin="2 0 2 2" Fill="Green">
                                                    <Rectangle.LayoutTransform>
                                                        <ScaleTransform ScaleY="{Binding ScaleY, RelativeSource={RelativeSource AncestorType={x:Type local:BarChart}}}"/>
                                                    </Rectangle.LayoutTransform>
                                                </Rectangle>
                                                <TextBlock HorizontalAlignment="Center" Text="{Binding Key}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:HorizontalBarChart}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:HorizontalBarChart}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                                <!--<RowDefinition Height="Auto"/>-->
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock x:Name="PART_Title" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" Padding="10" Text="{TemplateBinding Title}"/>
                            <TextBlock x:Name="PART_VerticalAxisTitle"  Grid.Row="1" VerticalAlignment="Center" Padding="2" Text="{TemplateBinding VerticalAxisTitle}">
                                <TextBlock.LayoutTransform>
                                    <RotateTransform Angle="90"/>
                                </TextBlock.LayoutTransform>
                            </TextBlock>
                            <ScrollViewer Grid.Column="1" Grid.Row="1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
                                <ItemsControl x:Name="PART_Items" ItemsSource="{TemplateBinding ItemsSource}" Padding="4 0 4 4" HorizontalAlignment="Center">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Vertical"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Key}" Margin="2"/>
                                                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="1">
                                                    <Rectangle Height="20" Width="{Binding Value}" Margin="2" Fill="Green">
                                                        <Rectangle.LayoutTransform>
                                                            <ScaleTransform ScaleX="{Binding Scale, RelativeSource={RelativeSource AncestorType={x:Type local:HorizontalBarChart}}}"/>
                                                        </Rectangle.LayoutTransform>
                                                    </Rectangle>
                                                    <TextBlock VerticalAlignment="Center" Text="{Binding Value}"/>
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
